home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / pennmush.000 / pennmush-1.50-p8-linux.tar / pennmush / bigrams.c < prev    next >
C/C++ Source or Header  |  1992-03-25  |  924b  |  52 lines

  1. /* bigrams.c */
  2.  
  3. /* This is taken, with permission, from the UnterMUD code. */
  4.  
  5. #include    <stdio.h>
  6. #include    <ctype.h>
  7.  
  8. /* this code is not pretty, nor does it have to be */
  9. /* run as:
  10.  * zcat database.Z | bigrams | sort -n -r | head -128
  11.  * will give the 128 most used bigrams in the db. then edit bigrams.h
  12.  */
  13.  
  14.  
  15. main()
  16. {
  17.     int    counts[256][256];
  18.     int    last;
  19.     int    c;
  20.     int    nhigh = 0;
  21.     int    highest = 0;
  22.     int    lowest = 0;
  23.  
  24.     for(c = 0; c < 255; c++)
  25.         for(last = 0; last < 255; last++)
  26.             if(!isprint(c) || !isprint(last))
  27.                 counts[c][last] = -1;
  28.             else
  29.                 counts[c][last] = 0;
  30.  
  31.     while(1) {
  32.         c = getchar();
  33.         if(feof(stdin))
  34.             break;
  35.  
  36.         if(last == -1 || c == '\n') {
  37.             if(c != '\n')
  38.                 last = c;
  39.             continue;
  40.         }
  41.         if(counts[last][c] != -1)
  42.             counts[last][c]++;
  43.         last = c;
  44.     }
  45.  
  46.     for(c = 0; c < 255; c++)
  47.         for(last = 0; last < 255; last++)
  48.             if(counts[c][last] > 0)
  49.                 printf("%d \"%c%c\"\n",counts[c][last],c,last);
  50. }
  51.  
  52.